#coding=utf-8
from database.db_handler import MysqlHander
from my_http import MyHttp
import urllib.request
from bs4 import BeautifulSoup
import glob
import jieba
import re
import json

'''
属性枚举值入库
'''

class SimpleTask:
    def __init__(self, file, task_type):
        self.db = MysqlHander("config.ini")
        self.file = file
        self.task_type = task_type
    
    def write_db(self, business):
        b = business.strip().replace("\n", "")
        if len(b) == 0:
            return
        sql = "insert into simple_task (Ftask_info, Ftask_type, Fcreate_time, Fmodify_time) values "
        sql += "('" + b + "'," + str(self.task_type) + ", now(), now());"
        print(sql)
        try:
            self.db.execute_not_safe(sql)
        except Exception as e:
            pass
    
    def record_attr(self):
        with open(self.file, 'r', encoding='utf-8') as f:
            self.business = f.readlines()
        for b in self.business:
            self.write_db(b)

if __name__ == '__main__':
    code = SimpleTask('./out/shenjiaosuo_zhishu_list_data.txt', 1000)
    code.record_attr()
    code1 = SimpleTask('./out/shangjiaosuo_zhishu_list_data.txt', 1001)
    code1.record_attr()